package com.ytjj.qmyx.mall.mapper;

import com.ytjj.qmyx.mall.model.*;
import com.ytjj.qmyx.mall.model.dto.OldForNewProductDto;
import com.ytjj.qmyx.mall.model.request.QueryOrdersRequest;
import com.ytjj.qmyx.mall.model.response.ActivityProductResponse;
import com.ytjj.qmyx.mall.model.response.OrderInfoResponse;
import com.ytjj.qmyx.users.model.UsersInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.math.BigDecimal;

/**
 * 订单dao
 *
 *
 * @version 1.0
 *
 */
public interface OrdersDao {

    /**
     * 根据外部订单获取支付信息
     *
     * @param resOrderNo
     * @return
     */
    OrdersPay queryOrdersPayByResOrderNo(@RequestParam("resOrderNo") String resOrderNo);

    /**
     * 根据orderNo获取订单信息
     *
     * @param orderNo
     * @return
     */
    Orders queryOrdersByOrderNo(@RequestParam("orderNo") String orderNo);

    /**
     * 查询订单列表
     *
     * @param ordersRequest
     * @return
     */
    List<Orders> queryOrdersList(QueryOrdersRequest ordersRequest);

    /**
     * 根据订单商品名称查询订单列表
     *
     * @param ordersRequest
     * @return
     */
    List<Orders> queryOrdersListByName(QueryOrdersRequest ordersRequest);

    /**
     * 根据活动类型获取订单明细
     * @param userId
     * @return
     */
    List<OrdersInfo> getOrderInfoListByActivityType(@RequestParam("userId") Integer userId,
                                                    @RequestParam("activityType") String activityType);
    /**
     * 根据手机号查询订单列表
     *
     * @param ordersRequest
     * @return
     */
    List<Orders> queryOrdersListByTel(QueryOrdersRequest ordersRequest);

    PayConfig getPayConfigByCompany(@Param("company") String company, @Param("type") String type,
                                    @Param("tradeType") String tradeType);

    Integer getOrdersInfoCount(@Param("userId") Integer userId);

    /**
     * 查询购买清单数量
     * @param userId
     * @return
     */
    Long countOrderInfoCountByUserId(@Param("userId") Integer userId);

    /**
     * 根据H5Token 获取订单信息
     * @param h5Token
     * @param name
     * @return
     */
    List<OrdersInfo> getOrderInfoListByToken(@Param("h5Token") String h5Token,
                                             @Param("activityType") String name);

    /**
     * 根据商品id查询商品明细
     *
     * @param orderId
     * @return
     */
    List<OrdersInfo> getOrdersInfoList(@Param("orderId") Integer orderId);

    /**
     * 根据手机号查询是否有支付订单
     * @param tel
     */
    Integer queryCountByTel(String tel);

    /**
     * 查询h5下单的订单
     * @param token
     * @return
     */
    List<Orders> queryNewUsersOrderIdH5(String token);

    List<Orders> queryNewUsersOrderIdH5Limit(String token);

    BigDecimal queryH5TotalUsedScore(String token);

    List<Integer> getProductStatusByOrderNo(@Param("orderId") Integer orderId);


    List<OldForNewProductDto> queryOldForNewOrdersProductList(@Param("h5Token") String token);

    Integer queryIsBuyFree(String token);

    OrdersPay findOrderPayByOrderId(Integer orderId);

    List<OrdersPay> findOrderPayListByOrderId(Integer orderId);

    List<OrdersPay> findOrderPayListByOrderNo(@Param("orderNo") String orderNo);

    List<OrderInfoResponse> findByOrderId(@Param("orderId")Integer orderId, @Param("ordersInfoId") Integer ordersInfoId);

    Dynamic findAllById(Integer id);

    UsersInfo findUserInfoById(Integer id);

    Integer selectByOrderNo(String newOrderCode);

    Integer selectByChildOrderNo(String childOrderNo);

    List<Orders> queryOrdersListOrder(QueryOrdersRequest ordersRequest);

    List<Orders> queryOrdersListByUserPhone(QueryOrdersRequest ordersRequest);

    List<Orders> queryOrdersListAll(QueryOrdersRequest ordersRequest);

    //保存运费信息
    void insertOrdersInfoFreight(OrdersInfoFreightDto ordersInfoFreightDto);

    List<OrdersInfo> findProductCount(Integer orderId);

    OrdersInfoFreightDto selectFreightByChildOrderNo(String childOrderNo);

    void updateFreight(@Param("totalFreight") BigDecimal totalFreight, @Param("childOrderNo") String childOrderNo);

    List<Integer> selectByProductId(@Param("productId") Integer productId);

    PayConfig getPayConfig(String company,String type,
                           String tradeType, String mchType);

    /**
     * 根据订单id修改订单状态
     * @param orderId
     * @return
     */
    Integer updateStatusByOrderId(@Param("ordersinfoStatus") String ordersinfoStatus,
                                  @Param("orderId") Integer orderId);

    String getSysConfig(String key);

    void updateUserOpenId(Integer userId,String openId);

    Integer updateStatusByOid(@Param("id") Integer id, @Param("ordersinfoStatus") String ordersinfoStatus, @Param("closeRemarks") String closeRemarks);

    Integer updateOrderStatusById(@Param("id") Integer id, @Param("ordersinfoStatus") String ordersinfoStatus, @Param("refundNo") String refundNo);



    void modifiedReturnRegister(@Param("orderInfoId") Integer orderInfoId);

    void updateOrderRefundStatus(Integer status,String tradeNo,String res_text);

    void updateOrderRefundStatusByTradeNo(Integer status,String tradeNo,String res_text);

    void updateOrderRefundStatusByRefundNo(Integer status,String refundNo,String res_text);

    Integer findOrderInfoIdByRefund(Integer id);

    Integer findOrderInfoIdByTradeNo(String tradeNo);

    Integer findOrderInfoIdByRefundNo(String refundNo);

    ReturnGoods selectReturnGoodsByWaitBackAmount(@Param("ordersInfoId") Integer ordersInfoId);

    void updateDomainUrlStateByUrl(String url);

    String getUrlNewContent(String domainUrl);

    void updateOrderAddress(Integer id,String tel,String address,String newTel,String userName);

    void updateAlipayFlag();

}
